package com.kensure.shike.weixin.service;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import co.kensure.frame.JSBaseService;
import co.kensure.http.HttpUtils;
import co.kensure.mem.DateUtils;

import com.alibaba.fastjson.JSONObject;

/**
 * 微信发送模板信息业务
 * 
 * @author fankd created on 2019-2-20
 * @since
 */
@Service
public class WeixinNoticeService extends JSBaseService {

	@Resource
	private WeixinSignService weixinSignService;

	/**
	 * 账号异常时发送的信息
	 */
	public  void sendZhanghaoYC(String openId,String phone) {
		String templateId = "b7DrcGICb054LUYmt9kG82Vm0D6-MBtjXo1VLtrUfnU";
		String goUrl = "http://www.52shibei.com/shike/skm/modifytaobao";

		JSONObject first = new JSONObject();
		first.put("value", "嗨，您手机号"+phone+"在试呗网绑定的淘宝账号存在异常");
		first.put("color", "#173177");

		JSONObject keyword1 = new JSONObject();
		keyword1.put("value", "【试呗网】");
		keyword1.put("color", "#173177");

		JSONObject keyword2 = new JSONObject();
		keyword2.put("value", "账号审核不通过！");
		keyword2.put("color", "#173177");

		JSONObject remark = new JSONObject();
		remark.put("value", "请到账户安全修改，或联系客服微信：17135507314，以免影响正常使用。");
		remark.put("color", "#173177");

		JSONObject data = new JSONObject();
		data.put("first", first);
		data.put("keyword1", keyword1);
		data.put("keyword2", keyword2);
		data.put("remark", remark);
		
		JSONObject json = new JSONObject();
		json.put("touser", openId);
		json.put("template_id", templateId);
		json.put("url", goUrl);
		json.put("topcolor", "#FF0000");
		json.put("data", data);
		
		sendCMS(json);
	}

	
	/**
	 * 支付宝异常时发送的信息
	 */
	public void sendZhifubaoYC(String openId,String phone) {
		String templateId = "b7DrcGICb054LUYmt9kG82Vm0D6-MBtjXo1VLtrUfnU";
		String goUrl = "http://www.52shibei.com/shike/skm/modifyalipay";

		JSONObject first = new JSONObject();
		first.put("value", "嗨，您手机号"+phone+"在试呗网绑定的支付宝账号存在异常");
		first.put("color", "#173177");

		JSONObject keyword1 = new JSONObject();
		keyword1.put("value", "【试呗网】");
		keyword1.put("color", "#173177");

		JSONObject keyword2 = new JSONObject();
		keyword2.put("value", "无法提现！");
		keyword2.put("color", "#173177");

		JSONObject remark = new JSONObject();
		remark.put("value", "请到账户安全修改，或联系客服微信：17135507314，以免影响正常使用。");
		remark.put("color", "#173177");

		JSONObject data = new JSONObject();
		data.put("first", first);
		data.put("keyword1", keyword1);
		data.put("keyword2", keyword2);
		data.put("remark", remark);
		
		JSONObject json = new JSONObject();
		json.put("touser", openId);
		json.put("template_id", templateId);
		json.put("url", goUrl);
		json.put("topcolor", "#FF0000");
		json.put("data", data);
		
		sendCMS(json);
	}
	
	/**
	 * 发送中奖结果
	 */
	public void sendZjjg(String openId,String phone,String title,String time) {
		String templateId = "VchbVGOxM4RJrVcOlZNykGGW5f5owbJRa4pkzoFWpkM";
		String goUrl = "http://www.52shibei.com/shike/skm/wdhd";

		JSONObject first = new JSONObject();
		first.put("value", "恭喜您手机号"+phone+"获得奖品"+title);
		first.put("color", "#173177");

		JSONObject keyword1 = new JSONObject();
		keyword1.put("value", "【试呗网】");
		keyword1.put("color", "#173177");

		JSONObject keyword2 = new JSONObject();
		String now = DateUtils.format(new Date());
		keyword2.put("value", now);
		keyword2.put("color", "#173177");

		JSONObject remark = new JSONObject();
		remark.put("value", "请在"+time+"内到淘宝下单，并上传截图和订单号。");
		remark.put("color", "#173177");

		JSONObject data = new JSONObject();
		data.put("first", first);
		data.put("keyword1", keyword1);
		data.put("keyword2", keyword2);
		data.put("remark", remark);
		
		JSONObject json = new JSONObject();
		json.put("touser", openId);
		json.put("template_id", templateId);
		json.put("url", goUrl);
		json.put("topcolor", "#FF0000");
		json.put("data", data);
		
		sendCMS(json);
	}
	
	/**
	 * 发送提现到账通知
	 */
	public void sendTxdz(String openId,String phone,Date tixiandate,Double txjine,Double shouxufei,Double daozhangjine) {
		String templateId = "20pHYQ4nOs5WFoEqmlV-7E8Qp2et6eO9S2C5CQ-ALUw";
		String goUrl = "http://www.52shibei.com/shike/skm/mine";

		JSONObject first = new JSONObject();
		first.put("value", "恭喜您手机号"+phone+"您申请的提现金额已到帐.");
		first.put("color", "#173177");
		
		JSONObject keyword1 = new JSONObject();
		String now = DateUtils.format(tixiandate);
		keyword1.put("value", now);
		keyword1.put("color", "#173177");
		
		JSONObject keyword2 = new JSONObject();
		keyword2.put("value", "支付宝");
		keyword2.put("color", "#173177");
		
		JSONObject keyword3 = new JSONObject();
		keyword3.put("value", txjine+"");
		keyword3.put("color", "#173177");
		
		JSONObject keyword4 = new JSONObject();
		keyword4.put("value", shouxufei+"");
		keyword4.put("color", "#173177");
		
		JSONObject keyword5 = new JSONObject();
		keyword5.put("value", daozhangjine+"");
		keyword5.put("color", "#173177");


		JSONObject remark = new JSONObject();
		remark.put("value", "感谢你的使用.");
		remark.put("color", "#173177");

		JSONObject data = new JSONObject();
		data.put("first", first);
		data.put("keyword1", keyword1);
		data.put("keyword2", keyword2);
		data.put("keyword3", keyword3);
		data.put("keyword4", keyword4);
		data.put("keyword5", keyword5);
		data.put("remark", remark);
		
		JSONObject json = new JSONObject();
		json.put("touser", openId);
		json.put("template_id", templateId);
		json.put("url", goUrl);
		json.put("topcolor", "#FF0000");
		json.put("data", data);
		
		sendCMS(json);
	}
	
	/**
	 * 发送微信信息
	 */
	private void sendCMS(JSONObject json) {
		String access_token = weixinSignService.getToken();
//		String access_token = "20_7cF6i4Wp15ofmb0YKzv8SgGG72nW_TSQsCtPEPI0wIM8CynbuCTAGrmtlUEoH2NHMdAmpNRebdTj7cpJTMWNsDCAy1uDEHtfLgQsSRmCdec7Mb8vQaW2F2GUMxoGFAcAEAYXS";
		String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;

		String d = HttpUtils.doPost(url, json);
		System.out.println(d);
	}
	
	
	public static void main(String[] args) {
//		sendZjjg("ojDqb1UPmQ8jnm5lOr9LR-MsVkig", "13606816944","type-c数据线1 ");
	}
	

}
